﻿using Demo.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using Dapper;
using System.Configuration;

namespace Demo.Helper
{

    public static class DapperHelper
    {

        public static string ConStr
        {
            get
            {
                //return ConfigurationManager.AppSettings.Get("default"); 
                return ConfigurationManager.ConnectionStrings["default"].ConnectionString; 
            }
        }

        private static SqlConnection GetSqlConnection()
        {
            SqlConnection conn = new SqlConnection(ConStr);
            conn.Open();
            return conn;
        }
        public static List<BaseUser> GetList()
        {
            List<BaseUser> userlist = new List<BaseUser>();
            var con = GetSqlConnection();
            userlist = con.Query<BaseUser>(@"select * from BaseUser").ToList();
            return userlist;
        }
    }
}

/*
 教程：
 * http://www.cnblogs.com/dunitian/p/4523006.html#dapper
 
 */